<%@ page import="com.jiuling.apis.zook.Global" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/jsp/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>信息编辑窗体</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link href="${ctxStatic}/plugins/h+/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/animate.min.css" rel="stylesheet">
    <%--<link href="${ctxStatic}/plugins/h+/css/style.min862f.css?v=4.1.0" rel="stylesheet">--%>
    <link rel="stylesheet" type="text/css" href="${ctxStatic}/plugins/h+/css/plugins/webuploader/webuploader.css">
    <link href="${ctxStatic}/plugins/h+/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">

    <link href="${ctxStatic}/plugins/h+/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/colorpicker/css/bootstrap-colorpicker.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/cropper/cropper.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/switchery/switchery.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/jasny/jasny-bootstrap.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/nouslider/jquery.nouislider.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/ionRangeSlider/ion.rangeSlider.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/ionRangeSlider/ion.rangeSlider.skinFlat.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/clockpicker/clockpicker.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/animate.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/style.min.css?v=4.0.0" rel="stylesheet"><base target="_blank">

    <style>
        .dtupload>img{
            width: 54px;
            padding-left: 39px;
            padding-top: 16px;
        }
        .dtupload>a{
            color: #268eff;
            font-size: 12px;
            position: relative;
            left: 26px;
            top: 10px;
        }.dtupload>a:hover,
         .shoplogo>a:hover{
             color:#F93;
         }.upload_pic {
              height: 70px;
              width:70px;
              position: relative;
              cursor: pointer;
              color: #ccbe9e;
              background: #fff;
              overflow: hidden;
              display: inline-block;
              *display: inline;
              *zoom: 1;
          }
        .upload_pic input {
            position: absolute;
            height:100%;
            width:100%;
            right: 0;
            top: 0;
            opacity: 0;
            filter: alpha(opacity=0);
            cursor: pointer
        }
        .upload_pic:hover {
            color: #ccbe9e;
            background: #fff;
            text-decoration: none
        }
        .posabs{
            position: absolute;
            right: 23px;
            top: 9px;
        }
        .chosen-container{
            width:100% !important;
        }
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="panel-options">
        <ul class="nav nav-tabs">
            <li class="active"><a data-toggle="tab" href="tabs_panels.html#tab-0"><i class="fa fa-laptop">基本信息</i></a>

            </li>
            <li class=""><a data-toggle="tab" href="tabs_panels.html#tab-1"><i class="fa fa-desktop">支付配置</i></a>
            </li>

        </ul>
    </div>

    <div class="panel-body">
        <form class="form-horizontal" onsubmit="return  false" id="merchantForm">
            <div class="tab-content">
                <div id="tab-0" class="tab-pane active">
                    <div class="ibox-content">
                        <input type="hidden" id="merchantId" name="pmerchant.id" value="${merchant.id}">
                        <input type="hidden" id="strategyId" name="pmerchant.strategyId" value="${merchant.strategyId}">
                    <%--<c:if test="${merchant.state ==0}">--%>
                            <%--<div class="form-group">--%>
                                <%--<div class="col-sm-1"></div>--%>
                                <%--<label class="col-sm-3 control-label" style="color: red;">*当前账号未审核，无法使用</label>--%>
                            <%--</div>--%>
                        <%--</c:if>--%>


                        <div class="form-group">
                            <label class="col-sm-3 control-label">商户LOGO：</label>
                            <div class="col-sm-4">
                                <!--上传logo-->
                                <input type="hidden" id="picid2" name="pmerchant.logo" value="${merchant.logo}">
                                <div class="dtupload">
                                    <a href="javascript:;" class="upload_pic" style="height:80px;">
                                        <img id="f03" src="${pageContext.request.contextPath}/resources/image/logopic1.png" width="100%" height="100%"/>
                                    </a>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">商户名称：</label>
                            <div class="col-sm-9">
                                <input type="text" readonly placeholder="商户名称" class="form-control" id="name" name="pmerchant.name" value="${merchant.name}">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">所属行业：</label>
                            <div class="col-sm-4">
                                <select id="category_first_select" data-placeholder="选择类目..." class="chosen-select" name="pmerchant.category"    onchange="ajaxCategorySecond(this)"   class="form-control">
                                </select>
                            </div>
                            <div class="col-sm-4">
                                <select id="category_second_select" data-placeholder="选择类目..." class="chosen-select"  name="pmerchant.category_sub"     class="form-control">
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">所属省市：</label>
                            <div class="col-sm-4">
                                <select id="pro_sel"  name="pmerchant.province"  onchange="loadCity(this.value)"  data-placeholder="选择省份..." class="chosen-select" style="width:100%" tabindex="2">

                                </select>
                            </div>
                            <div class="col-sm-4">
                                <select id="city_sel"  name="pmerchant.city" data-placeholder="选择城市..." class="chosen-select" style="width:100%" tabindex="2">

                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">联系方式：</label>
                            <div class=" col-sm-9">
                                <input type="number" id="phone"  name="pmerchant.phone" placeholder="请输入联系方式" class="form-control" value="${merchant.phone}">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">详细地址：</label>
                            <div class=" col-sm-9">
                                <input type="text" id="address"  name="pmerchant.address" placeholder="请输入详细地址" class="form-control" value="${merchant.address}">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">Auth Code：</label>
                            <div class=" col-sm-9">
                                <input readonly type="text" id="authCode"  name="pmerchant.authCode" placeholder="" class="form-control" value="${merchant.auth_code}">
                                注：Auth Code在商户通过审核后会自动生成
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-sm-offset-3 col-sm-8">
                                <button class="btn btn-primary" onclick="doSubmit();">审核通过</button>
                                <%--<button onclick="close();"  class="btn btn-primary" type="button">关闭</button>--%>
                            </div>
                        </div>
                    </div>

                </div>

                <div id="tab-1" class="tab-pane">
                    <div class="ibox-content">


                        <%--<c:if test="${merchant.state ==0}">--%>
                            <%--<div class="form-group">--%>
                                <%--<div class="col-sm-1"></div>--%>
                                <%--<label class="col-sm-3 control-label" style="color: red;">*当前账号未审核，无法使用</label>--%>
                            <%--</div>--%>
                        <%--</c:if>--%>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">发放方式:</label>
                            <div class=" col-sm-9">
                                <div class="radio radio-inline">
                                    <input type="radio" id="r0" value="0" name="pmerchant.type" onclick="changeRadio(0)">
                                    <label for="r0">发券</label>
                                </div>
                                <div class="radio radio-inline">
                                    <input type="radio" id="r1" value="1" name="pmerchant.type"  onclick="changeRadio(1)">
                                    <label for="r1">发贝</label>
                                </div>
                                <div class="radio radio-inline">
                                    <input type="radio" id="r2" value="2" name="pmerchant.type" onclick="changeRadio(2)">
                                    <label for="r2">发券并发贝</label>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">发券比例:</label>
                            <div class=" col-sm-5">
                                <select disabled  id="couponRate"  name="pmerchant.couponRate"  data-placeholder="选择发券比例..." class="chosen-select" style="width:100%" tabindex="1">

                                </select>
                                注：以2:1为例：100元 实际发券为50券
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">发贝比例:</label>
                            <div class=" col-sm-5">
                                <select disabled id="coinRate"  name="pmerchant.coinRate"  data-placeholder="选择发贝比例..." class="chosen-select" style="width:100%" tabindex="1">

                                </select>
                                注：以2:1为例：100券 实际发贝为50贝
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">服务费率:</label>
                            <div class=" col-sm-5">
                                <input type="text" id="feeRate" name="pmerchant.feeRate" placeholder="" class="form-control"  value="${merchant.fee_rate}">
                                注：以0.1为例：100元 实际手续费为10元<br>
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;服务费率由系统管理员在审核商户时设置
                            </div>
                        </div>


                        <div class="form-group">
                            <div class="col-sm-offset-3 col-sm-8">
                                <button class="btn btn-primary" onclick="doSubmit();">审核通过</button>
                                <%--<button onclick="close();"  class="btn btn-primary" type="button">关闭</button>--%>
                            </div>
                        </div>

                    </div>

                </div>


            </div>
        </form>

    </div>
</div>

</body>
<script src="${ctxStatic}/plugins/h+/js/jquery.min.js?v=2.1.4"></script>

<!-- 配置文件 -->
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/plugins/utf8-jsp/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/plugins/utf8-jsp/ueditor.all.js"></script>
<script src="${ctxStatic}/plugins/h+/js/content.min.js?v=1.0.0"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/validate/jquery.validate.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/validate/messages_zh.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/demo/form-validate-demo.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/layer2.4/layer.js"></script>

<script src="${ctxStatic}/plugins/h+/js/bootstrap.min.js?v=3.3.5"></script>
<script src="${ctxStatic}/plugins/h+/js/content.min.js?v=1.0.0"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/chosen/chosen.jquery.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/jsKnob/jquery.knob.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/jasny/jasny-bootstrap.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/datapicker/bootstrap-datepicker.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/prettyfile/bootstrap-prettyfile.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/nouslider/jquery.nouislider.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/switchery/switchery.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/ionRangeSlider/ion.rangeSlider.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/iCheck/icheck.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/colorpicker/bootstrap-colorpicker.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/clockpicker/clockpicker.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/cropper/cropper.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/demo/form-advanced-demo.min.js"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/ajaxfileupload.js"></script>

<script src="${pageContext.request.contextPath}/resources/plugins/ueditor1_4_2-utf8-jsp/ueditor.config.js"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/ueditor1_4_2-utf8-jsp/ueditor.all.min.js"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/ueditor1_4_2-utf8-jsp/lang/zh-cn/zh-cn.js"></script>



<script type="text/javascript">
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    var picPath='<%=Global.getConfig("OSSURL")%>';

    var proId="${merchant.province}";
    var cityId="${merchant.city}";
    var category_first="${merchant.category}";
    var category_second="${merchant.categorySub}";
    var coupon_rate="${merchant.coupon_rate}";
    var coin_rate="${merchant.coin_rate}";
    var areaData;



    function load() {
        var id='${merchant.id}';
        if(id!=null && id!=''){
            $("#f03").attr("src",picPath + '${merchant.logo}');
            var type = '${merchant.type}';
            var radioId = 'r' + type;
            console.log(radioId);
            $("#"+radioId).attr("checked","checked");
            console.log(coin_rate);
            console.log(coupon_rate);
            changeRadio(-1);
            matchCouponCoinSelect();

            $("#name").attr('disabled', true);
            $("#category_first_select").attr('disabled', true);
            $("#category_second_select").attr('disabled', true);
            $("#pro_sel").attr('disabled', true);
            $("#city_sel").attr('disabled', true);
            $("#phone").attr('disabled', true);
            $("#address").attr('disabled', true);
            $("input[name='pmerchant.type']").attr('disabled', true);
//            $("#couponRate").attr('disabled', true);
//            $("#coinRate").attr('disabled', true);
            <%--$("#feeRate").val('${merchant.fee_rate}');--%>

        }

    }


    $(function () {


    });

    ajaxCategoryFirst();
    loadFFBL();
    //加载省份
    loadPr();
//    showIndustry();
//    pbrand_pro();
    <%--pbrand_city("${prov}");--%>
    load();

    function loadFFBL() {
        $("#couponRate").chosen("destroy");
        var html='  <option value="">请选择</option>'+
                '<option value="1.00">1:1</option>' +
                '<option value="0.50">2:1</option>'  +
                '<option value="0.20">5:1</option>'  +
                '  <option value="0.10">10:1</option>';
        $("#couponRate").html(html);
        $("#couponRate").chosen({
            no_results_text : "未找到此选项!",
            width:"100%"
        });


        $("#coinRate").chosen("destroy");
        var html='  <option value="">请选择</option>'+
                '<option value="1.00">1:1</option>' +
                '<option value="0.50">2:1</option>'  +
                '<option value="0.20">5:1</option>'  +
                '  <option value="0.10">10:1</option>';
        $("#coinRate").html(html);
        $("#coinRate").chosen({
            no_results_text : "未找到此选项!",
            width:"100%"
        });



    }

    function matchCouponCoinSelect(){
        if(coupon_rate!=null&&coupon_rate!=""){
            $('#couponRate').val(coupon_rate);
        }
        $("#couponRate").trigger("chosen:updated");

        if(coin_rate!=null&&coin_rate!=""){
            $('#coinRate').val(coin_rate);
        }
        $("#coinRate").trigger("chosen:updated");
    }

    //加载一级类目
    function ajaxCategoryFirst()
    {
        $.ajax( {
            url:'${pageContext.request.contextPath}/merchant/queryCategoryFirst.ac?guid='+new Date().getTime(),// 跳转到 action
            data:{},
            type:'post',
            cache:false,
//            dataType:'json',
            success:function(data) {
                data=eval("(" + data + ")");
                if (data.length>0)
                {
                    var selected = '';
                    for (var i=0;i<data.length;i++)
                    {
                        var html = '<option value="'+data[i].category_code+'">'+data[i].category_name+'</option>';
                        $('#category_first_select').append(html);
                    }
//                $('#category_first_select').chosen({
//                    no_results_text : "未找到此选项!",
//                    width:"100%"
//                });
                    $('#category_first_select').chosen({
                        no_results_text : "未找到此选项!",
                        width:"100%"
                    });
                    if(category_first!=null&&category_first!=""){
                        $('#category_first_select').val(category_first);
                    }
                    $("#category_first_select").trigger("chosen:updated");
                    //加载二级类目
                    ajaxCategorySecond();
                }
            },
//            error : function() {
//                alert("操作失败！");
//            }
        });
    }

    //加载二级类目
    function ajaxCategorySecond()
    {
        var parent_code=$("#category_first_select").val();
        $('#category_second_select').html("");
        $.ajax( {
            url:'${pageContext.request.contextPath}/merchant/queryCategoryByParent.ac?parent_code='+parent_code+'&guid='+new Date().getTime(),// 跳转到 action
            data:{},
            type:'post',
            cache:false,
//            dataType:'json',
            success:function(data) {
                data=eval("(" + data + ")");
                if (data.length>0)
                {
                    var selected = '';
                    for (var i=0;i<data.length;i++)
                    {
                        var html = '<option value="'+data[i].category_code+'">'+data[i].category_name+'</option>';
                        $(html).appendTo('#category_second_select');
                    }
                    $('#category_second_select').chosen({
                        no_results_text : "未找到此选项!",
                        width:"100%"
                    });
                    if(category_second!=null&&category_second!=""){
                        $('#category_second_select').val(category_second);
                    }
                    $("#category_second_select").trigger("chosen:updated");
                }

            },
        });
    }

    function loadPr()
    {
        $.ajax( {
            url:'${pageContext.request.contextPath}/area/getArea.ac',// 跳转到 action
            data:{},
            type:'post',
            cache:false,
            dataType:'json',
            success:function(data) {
                areaData=data;
                $("#pro_sel").chosen("destroy");
                var html='<option value="">请选择</option>';
                for(var i=0;i<data.pro.length;i++)
                {

                    html+='<option value="'+data.pro[i].id+'">'+data.pro[i].text+'</option>';

                }
                $("#pro_sel").html(html);
                $('#pro_sel').chosen({
                    no_results_text : "未找到此选项!",
                    width:"100%"
                });

                if(proId!=null&&proId!=''&&proId!=undefined)
                {

                    $("#pro_sel").val(proId);
                    $("#pro_sel").trigger("chosen:updated");
                    loadCity(proId);
                }
            },
            error : function() {
                alert("加载代理商列表失败！");
            }
        });
    }
    function loadCity(id)
    {
        //  var id=obj.value;
        var data=areaData;
        $("#city_sel").chosen("destroy");

        var html='<option value="">请选择</option>';
        for(var i=0;i<data.city.length;i++)
        {
            if(data.city[i].pid==id)
            {
                html+='<option value="'+data.city[i].id+'">'+data.city[i].text+'</option>';
            }
        }
        $("#city_sel").html(html);
        $('#city_sel').chosen({
            no_results_text : "未找到此选项!",
            width:"100%"
        });
        $("#city_sel").trigger("chosen:updated");
        if(cityId!=null&&cityId!=''&&cityId!=undefined&&id==proId)
        {
            $("#city_sel").val(cityId);
            $("#city_sel").trigger("chosen:updated");
//            loadArea(cityId);
        }
    }

    function checkNumber(val) {
        var reg=/^[0-9]{1,}(?:.[0-9]{0,2})?$/;

        if(!reg.test(val))
        {
            alert("请正确输入数字,且保留小数点后2位");
        }
    }

    function changeRadio(type){
        console.log("changeRadio:"+type);
        if(type==0) {
            $("#couponRate").attr("disabled",false);
            $("#coinRate").attr("disabled",true);
        }else if(type==1) {
            $("#coinRate").attr("disabled",false);
            $("#couponRate").attr("disabled",true);
        }else if(type==2) {
            $("#couponRate").attr("disabled",false);
            $("#coinRate").attr("disabled",false);
        }else{
            $("#couponRate").attr("disabled",true);
            $("#coinRate").attr("disabled",true);
        }
        loadFFBL();


    }
    
    function doSubmit() {
        var reg=/^[0-9]{1,}(?:.[0-9]{0,2})?$/;
        var feeRate = $("#feeRate").val();
        if(feeRate==null||feeRate==undefined||feeRate==''){alert("请输入服务费率");return;}
        if(!reg.test(feeRate))
        {
            alert("请正确输入数字,且保留小数点后2位");
            return;
        }

        $.ajax( {
            url:'${pageContext.request.contextPath}/merchant/doApprove.ac',// 跳转到 action
            data:$("#merchantForm").serialize(),
            type:'post',
            cache:false,
            dataType:'json',
            success:function(data) {
                if(data.success==true)
                {
                    alert("操作成功！");
                    closeD();
                }else
                {
                    alert(data.msg);
                }
            },
            error : function() {
                alert("操作失败！");
            }
        });

    }

    function closeD() {
        console.log("close");
        parent.layer.close(index);
    }


</script>

</html>

